cc.Class({
    extends: cc.Component,

    properties: {
        whitetime:cc.Float,
        bluetime:cc.Float,
        redtime:cc.Float
    },

    // use this for initialization
    onLoad: function () {
        this.whitetime=this.redtime=this.bluetime=0;
    },

    // called every frame, uncomment this function to activate update callback
    update: function (dt) {
        
        if(this.node.color.equals(cc.Color.WHITE)){
            this.whitetime+=dt;
            if(this.whitetime>=2){  //每过2秒判断是否变蓝
                this.whitetime=0;
                var a=cc.random0To1();
                if(a>0.7){
                    this.node.color=cc.Color.BLUE;
                } 
            }
        }

        else if(this.node.color.equals(cc.Color.BLUE)){
            this.bluetime+=dt;
            if(this.bluetime>=1){   //蓝色持续1秒
                this.bluetime=0;
                this.node.color=cc.Color.WHITE;
            }
        }
        else if(this.node.color.equals(cc.Color.RED)){
            this.redtime+=dt;
            if(this.redtime>=2){   //红色持续2秒
                this.redtime=0;
                this.node.color=cc.Color.WHITE;
            }
        }
    },
});
